<?php
	require_once("search/imdb_search.class.php");
	require_once("search/imdb_search_title.class.php");
	require_once("search/imdb_search_tv.class.php");
	require_once("search/imdb_search_character.class.php");
	require_once("search/aka/imdb_search_aka.class.php");
	require_once("search/aka/imdb_search_aka_title.class.php");
	require_once("search/result/imdb_search_result.class.php");
	require_once("search/result/imdb_search_result_title.class.php");
	require_once("search/result/imdb_search_result_tv.class.php");
	class IMDB {
		const URL_BASE = "http://www.imdb.com";
		const URL_SEARCH = "http://www.imdb.com/find?s=%s&q=%s";
		
		public static $ENUM_SEARCH_TYPE = array(
			1	=>	array("tt", "Titles"),
			2	=>	array("ep", "Titles"),
			3	=>	array("nm", "Names"),
			4	=>	array("co", "Companies"),
			5	=>	array("kw", "Keywords"),
			6	=>	array("char", "Characters")
		);
		const SEARCH_TYPE_TITLES = 1;
		const SEARCH_TYPE_TV = 2;
		const SEARCH_TYPE_NAMES = 3;
		const SEARCH_TYPE_COMPANIES = 4;
		const SEARCH_TYPE_KEYWORDS = 5;
		const SEARCH_TYPE_CHARACTERS = 6;
		
		public static $ENUM_RESULT = array(
			0	=>	"Popular %s",
			1	=>	"%s (Exact Matches)",
			2	=>	"%s (Partial Matches)",
			3	=>	"%s (Approx Matches)"
		);
		const RESULT_ALL = -1;
		const RESULT_POPULAR = 0;
		const RESULT_EXACT = 1;
		const RESULT_PARTIAL = 2;
		const RESULT_APPROX = 3;
		
		public function Search($sQuery, $iType)
		{
			switch ($iType) {
				case IMDB::SEARCH_TYPE_TITLES:
					return new IMDB_Search_Title($sQuery, $iType);
					break;
				case IMDB::SEARCH_TYPE_TV:
					return new IMDB_Search_TV($sQuery, $iType);
					break;
				case IMDB::SEARCH_TYPE_CHARACTERS:
					return new IMDB_Search_Character($sQuery, $iType);
					break; 
				default:
					throw new Exception("Unknown search type requested in IMDB->Search");
			}
		}
	}
?>